package com.yueqian.web.controller;

import com.yueqian.domain.Account;
import com.yueqian.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.crypto.interfaces.PBEKey;
import java.util.List;

@Controller
@RequestMapping("/account")
public class AccountController {

    @Autowired
    AccountService accountService;

    @RequestMapping("/findAll")
    public ModelAndView findAll() throws Exception{
        //System.out.println("accountService: "+accountService);
        System.out.println("AccountController---findAll");
        List<Account> accounts = accountService.findAll();
        //System.out.println("AccountController   "+accounts);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("accounts",accounts);
        modelAndView.setViewName("list");
        return modelAndView;
    }

    @RequestMapping("/saveAccount")
    public String saveAccount(Account account) throws Exception{
        accountService.saveAccount(account);
        return "success";
    }
    @RequestMapping("/transfer")
    public String transfer() throws Exception{
        try {
            accountService.transfer();
        } catch (Exception e) {
            e.printStackTrace();
            //抛自定义异常
        }
        return "success";
    }
}
